package utility;

import java.util.concurrent.*;

public class ParameterizedCachedThreadPool implements ParameterizedExecutor {

	ExecutorService executor = Executors.newCachedThreadPool();
	
	@Override
	public void execute(Runnable command) {
		executor.execute(command);		
	}

	@Override
	public <T> void execute(ParameterizedRunnable<T> task, T parameter) {
		executor.execute( new ParameterizedRunnableAdapter<T>(task, parameter) );
	}
	
	class ParameterizedRunnableAdapter<T> implements Runnable
	{
		private ParameterizedRunnable<T> task;
		private T parameter;
		
		public ParameterizedRunnableAdapter (ParameterizedRunnable<T> task, T parameter) {
			this.task = task;
			this.parameter = parameter;
		}
		
		public void run() {
			task.run(parameter);
		}
	}

}
